import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/input_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'package:flutter/material.dart';

import 'register_controller.dart';


/// 注册
class RegisterPage extends GetView<RegisterController> {
  const RegisterPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.only(
            left: ScreenHelper.width(15),
            right: ScreenHelper.width(15),
            top: ScreenHelper.topSafeHeight + ScreenHelper.height(40)),
        child: Obx(() => Column(
              children: [
                Image.asset(
                  "assets/sign/logo.png",
                  width: ScreenHelper.width(100),
                  height: ScreenHelper.width(100),
                  package: "basic_common",
                ),
                SizedBox(
                  height: ScreenHelper.height(20),
                ),
                Text("注册",
                    style: TextStyle(
                        color: AppTheme.dartTextColor,
                        fontSize: ScreenHelper.sp(20),
                        fontWeight: FontWeight.bold)),
                SizedBox(
                  height: ScreenHelper.height(10),
                ),
                Text(
                  "欢迎使用家庭服务医生端",
                  style: TextStyle(
                      color: AppTheme.dartTextColor,
                      fontSize: ScreenHelper.sp(16)),
                  textAlign: TextAlign.center,
                ),
                SizedBox(
                  height: ScreenHelper.height(20),
                ),
                norTitle(title: "请输入手机号码"),
                inputBox(
                    inputController: controller.phoneController,
                    onChanged: (value) {
                      if (value.length == 11) {
                        controller.btnIsEnable.value = true;
                      } else {
                        controller.btnIsEnable.value = false;
                      }
                    }),
                const SizedBox(
                  height: 40,
                ),
                btnComponent(
                    onPressed: () {
                      if (controller.isRead.value) {
                        controller.postSmsCode();
                      } else {
                        ToastUtils.toast("请先阅读隐私协议");
                        controller.isRead.value = true;
                      }
                    },
                    isEnable: controller.btnIsEnable.value,
                    textStr: "下一步"),
                agreementWidget(controller.isRead.value, onChange: (value) {
                  controller.isRead.value = value!;
                }),
                Spacer(),
                SizedBox(
                  height: ScreenHelper.height(40),
                ),
                _bootomWidget()
              ],
            )),
      ),
    );
  }

  /// 底部 登录方式
  Widget _bootomWidget() {
    return Align(
      alignment: Alignment.bottomCenter,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(
            height: ScreenHelper.height(44),
            child: Text.rich(
              TextSpan(
                  style: TextStyle(
                      fontSize: ScreenHelper.sp(14),
                      color: AppTheme.weakTextColor,
                      height: 2.0),
                  children: [
                    const TextSpan(
                      text: "已有账号，",
                    ),
                    textLink("立即登录", type: 2, onTap: () {
                      Get.offAndToNamed(AppRoutes.login);
                    }),
                  ]),
              textAlign: TextAlign.left,
            ),
          ),
          SizedBox(
            height: ScreenHelper.height(60),
          )
        ],
      ),
    );
  }
}
